package com.haidada.tk.service.impl;

import com.haidada.tk.pojo.User;
import com.haidada.tk.repository.UserRepository;
import com.haidada.tk.service.UserService;
import com.haidada.tk.utils.ApiResponse;
import com.haidada.tk.utils.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

@Service
//@Transactional(readOnly = true)
public class UserServiceImpl implements UserService {

    @Autowired
    UserRepository userRepository;

    @Override
    public ApiResponse login(String openId) {
        User user = new User();
        user.setOpenId(openId);
        user.setId(IdUtils.getId());
        User save = userRepository.save(user);
        System.out.println(save);
        return ObjectUtils.isEmpty(save) ? ApiResponse.internalError() : ApiResponse.success();
    }
}
